﻿using iChip.Hotspots.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace iChip.Hotspots.Controllers
{
    public class AdminMethodsController : Controller
    {
        private BO.BOs _bo = new BO.BOs();
        public ActionResult Index(string called, string mac, int? user_type)
        {
            //"30-B5-C2-D5-E0-8F" E4-D5-3D-08-1D-05
            if (string.IsNullOrEmpty(called))
            {
                called = "30-B5-C2-D5-E0-8F";
            }

            if (string.IsNullOrEmpty(mac))
            {
                mac = "E4-D5-3D-08-1D-05";
            }
            var model = new IndexObject();
            model = _bo.Get_Field_by_Hotspot_Mac(called, user_type.GetValueOrDefault());
            ViewBag.Mac = mac;
            return View(model);
        }

        [HttpPost]
        public ActionResult PostInfo(List<RequestPostField> objRequest, string mac)
        {
            try
            {
                _bo.Insert_Values(mac, objRequest);
                return Json(new { Status = 1, Message = string.Empty });
            }
            catch (Exception ex)
            {
                return Json(new { Status = 0, Message = ex.Message });
            }
            
           
        }

        public ActionResult FieldCreate(int method_id, string returnUrl)
        {
            ViewBag.MethodId = method_id;
            ViewBag.ReturnUrl = returnUrl;
            return View();
        }

        [HttpPost]
        public ActionResult FieldCreated(List<RequestPostField> objRequest)
        {
            try
            {
                _bo.Insert_Fields(objRequest);
                return Json(new { Status = 1, Message = string.Empty });
            }
            catch(Exception ex)
            {
                return Json(new { Status = 0, Message = ex.Message });
            }
            
        }

        public ActionResult GenField()
        {
            var model = new FieldCreate();
            return PartialView(model);
        }

        public ActionResult ListMethods(int splash_id, string returnUrl)
        {
            var model = new List<Method>();
            model = _bo.Select_Method_by_SplashId(splash_id);
            ViewBag.ReturnUrl = returnUrl;
            return PartialView(model);
        }
	}
}